package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.CourseChangeRequest;
import com.hwadee.teachingprocessmanagementsystem.dao.CourseChangeRequestDao;
import com.hwadee.teachingprocessmanagementsystem.entity.Student;
import com.hwadee.teachingprocessmanagementsystem.entity.Teacher;
import com.hwadee.teachingprocessmanagementsystem.service.base.CourseChangeRequestService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

import java.util.List;

/**
 * 调课申请表(CourseChangeRequest)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("courseChangeRequestService")
public class CourseChangeRequestServiceImpl implements CourseChangeRequestService {
    @Resource
    private CourseChangeRequestDao courseChangeRequestDao;

    /**
     * 通过ID查询单条数据
     *
     * @param requestId 主键
     * @return 实例对象
     */
    @Override
    public CourseChangeRequest queryById(Integer requestId) {
        return this.courseChangeRequestDao.queryById(requestId);
    }

    /**
     * 分页查询
     *
     * @param courseChangeRequest 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CourseChangeRequest> queryByPage(CourseChangeRequest courseChangeRequest, PageRequest pageRequest) {
        long total = this.courseChangeRequestDao.count(courseChangeRequest);
        return new PageImpl<>(this.courseChangeRequestDao.queryAllByLimit(courseChangeRequest, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param courseChangeRequest 实例对象
     * @return 实例对象
     */
    @Override
    public CourseChangeRequest insert(CourseChangeRequest courseChangeRequest) {
        this.courseChangeRequestDao.insert(courseChangeRequest);
        return courseChangeRequest;
    }

    /**
     * 修改数据
     *
     * @param courseChangeRequest 实例对象
     * @return 实例对象
     */
    @Override
    public CourseChangeRequest update(CourseChangeRequest courseChangeRequest) {
        this.courseChangeRequestDao.update(courseChangeRequest);
        return this.queryById(courseChangeRequest.getRequestId());
    }

    /**
     * 通过主键删除数据
     *
     * @param requestId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer requestId) {
        return this.courseChangeRequestDao.deleteById(requestId) > 0;
    }

    @Override
    public List<CourseChangeRequest> queryAllByStudentNumber(Student student) {
        return this.courseChangeRequestDao.queryAllByStudentNumber(student);
    }

    @Override
    public List<CourseChangeRequest> queryAllByTeacherId(Teacher teacher) {
        return this.courseChangeRequestDao.queryAllByTeacherId(String.valueOf(teacher.getTeacherId()));
    }
}
